unit frmMenu;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls, ExtCtrls, DataModule, jvCSVBase, frmNamePicker, unTimer,
  unOutcomes, untRewards;

type

  { TfrmMenuScreen }

  TfrmMenuScreen = class(TForm)
    btnNamePicker: TButton;
    btnTimer: TButton;
    btnQuit: TButton;
    btnOutcomes: TButton;
    btnRewards: TButton;
    btnPick: TButton;
    cboClass: TComboBox;
    cboYear: TComboBox;
    edtTeacher: TEdit;
    lblClass: TLabel;
    frmTimer: TfrmTimer;
    frmRewards: TfrmRewards;
    frmNamePicker: TfrmNameSelection;
    frmOutcomes: TfrmOutcomes;
    frmPanel: TPanel;
    procedure btnNamePickerClick(Sender: TObject);
    procedure btnOutcomesClick(Sender: TObject);
    procedure btnPickClick(Sender: TObject);
    procedure btnQuitClick(Sender: TObject);
    procedure btnRewardsClick(Sender: TObject);
    procedure btnTimerClick(Sender: TObject);
    procedure cboClassSelect(Sender: TObject);
    procedure cboYearSelect(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
    procedure LoadData;
  public
    { public declarations }
  end; 

var
  frmMenuScreen: TfrmMenuScreen;

implementation

{ TfrmMenuScreen }

procedure TfrmMenuScreen.LoadData;
begin
  cboYear.Items.Add('7');
  cboYear.Items.Add('8');
  cboYear.Items.Add('9');
  cboYear.Items.Add('10');
  cboYear.Items.Add('11');
  cboYear.Items.Add('12');
  cboYear.Items.Add('13');
  DataModule1.InitData;
  cboClass.Items   := DataModule1.Classes;
end;

procedure TfrmMenuScreen.btnNamePickerClick(Sender: TObject);
begin
  if lblClass.Caption = 'Class' then
     showmessage('Please select a class first!')
  else
  begin
          if frmNamePicker <> Nil then
          begin
               frmNamePicker.Parent := frmPanel;
               frmNamePicker.btnLoadClick(Nil);
               frmNamePicker.Show;
               frmPanel.Refresh;

          end;
  end;
end;

procedure TfrmMenuScreen.btnOutcomesClick(Sender: TObject);
begin
  if lblClass.Caption = 'Class' then
     showmessage('Please select a class first!')
  else
  begin
          frmOutcomes.Parent := frmPanel;
          if (DataModule1.Group <> frmOUtcomes.Group) then
          begin
              frmOutcomes.ClearLabels(DataModule1.Group);
              frmOutcomes.CreateLabels;
          end;
          frmOutcomes.Show;
          frmPanel.Refresh;
  end;
end;

procedure TfrmMenuScreen.btnPickClick(Sender: TObject);
begin
  if edtTeacher.Text <> '' then
  begin
       DataModule1.Filtered:=True;
       DataModule1.Teacher:=edtTeacher.Text;
       DataModule1.InitData;
       cboClass.Items := DataModule1.Classes;
  end;
end;

procedure TfrmMenuScreen.btnQuitClick(Sender: TObject);
begin
  frmMenuscreen.Close;
end;

procedure TfrmMenuScreen.btnRewardsClick(Sender: TObject);
begin
  if lblClass.Caption = 'Class' then
     showmessage('Please select a class first!')
  else
  begin
       if (Datamodule1.Group <> frmRewards.Group) then
       begin
            frmRewards.ClearLabels(DataModule1.Group);
            frmRewards.CreateLabels;
       end;
       frmRewards.Parent := frmPanel;
       frmRewards.Show;
  end;

end;

procedure TfrmMenuScreen.btnTimerClick(Sender: TObject);
begin
     frmTimer.Parent := frmPanel;
     frmTimer.Show;
end;

procedure TfrmMenuScreen.cboClassSelect(Sender: TObject);
begin
  lblClass.caption := cboClass.caption;
  DataModule1.Group:=cboClass.caption;
  DataModule1.LoadClassList;
end;

procedure TfrmMenuScreen.cboYearSelect(Sender: TObject);
begin
   DataModule1.Filtered:=True;
   DataModule1.Year:=cboYear.Caption;
   DataModule1.InitData;
   cboClass.Items := DataModule1.Classes;;
end;

procedure TfrmMenuScreen.FormCreate(Sender: TObject);
begin
      frmTimer := TfrmTimer.Create(self);
      frmRewards := TfrmRewards.Create(self);
      frmOutcomes := TfrmOutcomes.Create(self);
      frmNamePicker := TfrmNameSelection.Create(self);
end;

procedure TfrmMenuScreen.FormDestroy(Sender: TObject);
begin
     frmTimer.Free;
     frmRewards.Free;
     frmOutcomes.Free;
     frmNamePicker.Free;
end;

procedure TfrmMenuScreen.FormShow(Sender: TObject);
begin
  LoadData;
end;

initialization
  {$I frmmenu.lrs}

end.

